/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package practicadwh;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
 *
 * @author yojugracu
 */
public class Tablas {
    
    public Tablas(){
        listaTablas = new Hashtable<String, DefaultTableModel>();
    }
    
    //-------------------- Agrega una tabla a la lista -----------------------//
    public void addTabla( String nombreTabla, String[] headers ){
        DefaultTableModel dtmModelo = new DefaultTableModel();
        for( String nomColumna : headers ){
            dtmModelo.addColumn( nomColumna );
        }
        if( !listaTablas.containsKey( nombreTabla ) ){
            listaTablas.put( nombreTabla, dtmModelo );
        }     
    }
    //------------------------------------------------------------------------//
    
    //------------------------- Obtiene la tabla -----------------------------//
    public JTable getTabla( String tabla ){
        DefaultTableModel dtmModelo = listaTablas.get( tabla );
        JTable table = new JTable();
        table.setModel( dtmModelo );
        return table;
    }
    //------------------------------------------------------------------------//
    
    public DefaultTableModel getMTable( String tabla ){
        return listaTablas.get( tabla );
    }
    
    //--------------------- Se agrega una fila a la tabla --------------------//
    public void addFila( String tabla, String[] row ){
        DefaultTableModel dtmModelo = listaTablas.get( tabla );
        dtmModelo.addRow( row );
    }
    //------------------------------------------------------------------------//
    
    //---------------------- Se agregan filas a la tabla ---------------------//
    public void addFilas( String tabla, ArrayList<String[]> rows ){
        List<String[]> lista = rows;
        for( String[] fila : lista  ){
            addFila( tabla, fila );
        }
    }
    //------------------------------------------------------------------------//
    
    public boolean existeTabla( String nombre ){
        if( listaTablas.containsKey( nombre ) ) return true;
        return false;
    }
    
    public void addArbol( DefaultTreeModel modelo, DefaultMutableTreeNode mutable ){
        Enumeration<String> e = listaTablas.keys();
        int i = 0;
        while( e.hasMoreElements() ){
            DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode( e.nextElement() );
            modelo.insertNodeInto( dmtn, mutable, i++ ); System.out.println(i);
        }
    }
    
    Hashtable<String, DefaultTableModel> listaTablas;
}
